<!--月度接受检查情况 acceptInspectSafeRpt-->
<template>
  <Layout>
    <Form ref="form1" :model="dataToQuery" :label-width="120" :loading="pageStatus.baseLoading">
      <Row  v-show="!switchFlag" class="query-form" >
        <Col span="8">
           <FormItem label="企业名称：" prop="companyId">
            <cascader-dom class="query-form-el" ref='queryOrgCascader' @setOrgInfo='setQueryCompanyName' :orgTree="true" :setCurrentName="{label:dataToQuery.companyName,value:dataToQuery.companyId}"></cascader-dom>
          </FormItem>
        </Col>
        <Col span="8">
          <FormItem label="月份：" prop="month" >
            <DatePicker class="query-form-el" v-model="dataToQuery.monthStart" format="yyyy-MM" type="month" placement="bottom-end" placeholder="请选择月份" style="width: 44%"
                        @on-change="(date) => { dataToQuery.monthFrom = date + '-01'}" :options="{disabledDate(date) {return date && dataToQuery.monthEnd && date.valueOf() > dataToQuery.monthEnd;}}"></DatePicker> -
            <DatePicker class="query-form-el" v-model="dataToQuery.monthEnd" format="yyyy-MM" type="month" placement="bottom-end" placeholder="请选择月份" style="width: 45%"
                        @on-change="monthToChange" :options="{disabledDate(date) {return date && dataToQuery.monthStart && date.valueOf() < dataToQuery.monthStart;}}"></DatePicker>
          </FormItem>
        </Col>
        <Col span="8">
          <Button @click="switchQuery(true)" class="ivu-btn-switch" type="text">展开∨</Button>
          <Button @click="reset" class="ivu-btn-reset"  >重置</Button>
          <Button type="primary" class="ivu-btn-query"   icon="md-search"  @click="query">查询</Button>
        </Col>
      </Row>
      <Row v-show="switchFlag" class="query-form">
        <Col span="8">
           <FormItem label="企业名称：" prop="companyId">
            <cascader-dom class="query-form-el" ref='queryOrgCascader' @setOrgInfo='setQueryCompanyName' :orgTree="true" :setCurrentName="{label:dataToQuery.companyName,value:dataToQuery.companyId}"></cascader-dom>
          </FormItem>
        </Col>
        <Col span="8">
          <FormItem label="月份：" prop="month" >
            <DatePicker class="query-form-el" v-model="dataToQuery.monthStart" format="yyyy-MM" type="month" placement="bottom-end" placeholder="请选择月份" style="width: 44%"
                        @on-change="(date) => { dataToQuery.monthFrom = date + '-01'}" :options="{disabledDate(date) {return date && dataToQuery.monthEnd && date.valueOf() > dataToQuery.monthEnd;}}"></DatePicker> -
            <DatePicker class="query-form-el" v-model="dataToQuery.monthEnd" format="yyyy-MM" type="month" placement="bottom-end" placeholder="请选择月份" style="width: 45%"
                        @on-change="monthToChange" :options="{disabledDate(date) {return date && dataToQuery.monthStart && date.valueOf() < dataToQuery.monthStart;}}"></DatePicker>
          </FormItem>
        </Col>
        <Col span="8">
          <FormItem label="年度：" prop="yearDate" >
            <DatePicker class="query-form-el" v-model="dataToQuery.yearDate" type="year"></DatePicker>
          </FormItem>
        </Col>
      </Row>
  <!--    <Row v-show="switchFlag" class="query-form" style="padding-top: 15px" >
        <Col span="8">
          <FormItem label="安全检查级别：">
            <Select multiple v-model='dataToQuery.saInspects' class='query-form-el'>
              <Option value="2">国家</Option>
              <Option value="1">省厅</Option>
              <Option value="0">区县</Option>
            </Select>
          </FormItem>
        </Col>
        <Col span="8">
          <FormItem label="环保检查级别：">
            <Select multiple v-model='dataToQuery.enInspects' class='query-form-el'>
              <Option value="2">国家部</Option>
              <Option value="1">省厅</Option>
              <Option value="0">区县</Option>
            </Select>
          </FormItem>
        </Col>
        <Col span="8">
          <FormItem label="因环境问题处罚、曝光：">
            <Select v-model='dataToQuery.punishTeims' class='query-form-el'>
              <Option value="1">是</Option>
              <Option value="0">否</Option>
            </Select>
          </FormItem>
        </Col>
      </Row>  -->
      <Row v-show="switchFlag" class="query-form">
        <Col span="8" offset="16">
          <Button @click="switchQuery(false)" class="ivu-btn-switch" type="text">收起∧</Button>
          <Button @click="reset" class="ivu-btn-reset">重置</Button>
          <Button class="ivu-btn-query" icon="md-search" @click="query">查询</Button>
        </Col>
      </Row>
      <Row class="query-form">
        <Col span="24">
          <!--<Button size="large"  class="ivu-btn-add" icon="md-add"  @click="addInfo">新增</Button>-->
          <Button type="primary" class="ivu-btn-add"   icon="md-cloud-download"  @click="exportFormSubmit" :loading="exportLoading">导出</Button>
        </Col>
      </Row>
    </Form>
    <Table ref='table' :height="tableHeight" :row-class-name="localRowClassName" no-data-text="没有查询到相关数据!" @on-selection-change = 'getSelectRows' :loading='pageStatus.loading || pageStatus.baseLoading'
           border :columns="columns1" @on-cell-click="cellClicked" :data="dataTable" >
    </Table>
    <Row style="margin-right:10px;">
      <Col span="24" >
        <Page style="float: right" :total="pagedata.total" :page-size="pagedata.pageSize" @on-change="pageChange" @on-page-size-change="pageSizeChange" :page-size-opts="pageSizeArray" show-total show-sizer show-elevator />
      </Col>
    </Row>
    <Modal  title="月度接受检查情况" :transfer=false :mask-closable="false" v-model="dialogShow" v-if="dataToView && dialogShow"  :width=800 :styles="{height:'692px'}"  class-name='limit-height-dialog'>
      <Row>
        <Col span="24">
          <Form ref="dialogForm" :class="mode === 'view'?'modal-view-detail':''" :show-message="false" :model="dataToView" :rules="mode === 'view'?{}:ruleCustom" :label-width="mode === 'view'?160:null" :label-position="mode === 'view'?'right':'top'">
            <Row type="flex" justify="space-around" class="code-row-bg">
              <Col span="23">
                <FormItem label='企业名称：' prop='companyId'>
                  <div v-if="mode === 'view'">{{dataToView.companyName}}</div>
                  <cascader-dom v-else ref='orgCascader' @setOrgInfo='setCompanyId' @setOrgname="setCompanyName" :orgTree="true" :currentOrgId = "dataToView.companyId"
                                :setCurrentName="{label:dataToView.companyName,value:dataToView.companyId}" ></cascader-dom>
                </FormItem>
              </Col>
            </Row>
            <Row type="flex" justify="space-around" class="code-row-bg">
              <Col span="11">
                <FormItem label='所在地：' prop='companyAddress'>
                  <div v-if="mode === 'view'">{{areaCodeToAreaName(dataToView.companyAddress)}}</div>
                  <Cascader v-else :data="tempAreaTree" v-model="dataToView.companyAddressArr" change-on-select :transfer="true"
                            :load-data="areaTreeLoadData" :render-format="labels=>labels.join('·')"  :clearable='false'
                            @on-change="(value,selectedData)=>{$set(dataToView,'companyAddress',value.join(','))}"></Cascader>
                </FormItem>
              </Col>
              <Col span="11">
                <FormItem label='月份：' prop='rptPeroid'>
                  <div v-if="mode === 'view'">{{dataToView.rptPeroid.substr(0,7)}}</div>
                  <DatePicker v-else class="query-form-el w" :editable='false' type="month" placeholder="请选择月份" v-model='dataToView.rptPeroid'
                  ></DatePicker>
                </FormItem>
              </Col>
            </Row>
            <Row type="flex" justify="space-around" class="code-row-bg">
              <Col span="11">
                <FormItem label='接受国家部、委环境督查检查：' prop='stateEnInspect'>
                  <div v-if="mode === 'view'">{{dataToView.stateEnInspect}}</div>
                  <InputNumber  v-else class="w" min="0" type='text' v-model='dataToView.stateEnInspect'></InputNumber>
                </FormItem>
              </Col>
              <Col span="11">
                <FormItem label='接受省、自治区、直辖市级环境督查检查：' prop='provinceEnInspect'>
                  <div v-if="mode === 'view'">{{dataToView.provinceEnInspect}}</div>
                  <InputNumber v-else class="w" min="0"  type='text' v-model='dataToView.provinceEnInspect'></InputNumber>
                </FormItem>
              </Col>
            </Row>
            <Row type="flex" justify="space-around" class="code-row-bg">
              <Col span="11">
                <FormItem label='接受属地市、区、县级环境督查检查：' prop='districtEnInspect'>
                  <div v-if="mode === 'view'">{{dataToView.districtEnInspect}}</div>
                  <InputNumber v-else class="w" min="0"  type='text' v-model='dataToView.districtEnInspect'></InputNumber>
                </FormItem>
              </Col>
              <Col span="11">
                <FormItem label='因环境保护问题受到处罚、曝光情况：' prop='enPunishTeims'>
                  <div v-if="mode === 'view'">{{dataToView.enPunishTeims}}</div>
                  <InputNumber v-else class="w" min="0"  type='text' v-model='dataToView.enPunishTeims'></InputNumber>
                </FormItem>
              </Col>
            </Row>
            <Row type="flex" justify="space-around" class="code-row-bg">
              <Col span="11">
                <FormItem label='接受国家部、委安全督查检查：' prop='stateSaInspect'>
                  <div v-if="mode === 'view'">{{dataToView.stateSaInspect}}</div>
                  <InputNumber v-else class="w" min="0"  type='text' v-model='dataToView.stateSaInspect'></InputNumber>
                </FormItem>
              </Col>
              <Col span="11">
                <FormItem label='接受省、自治区、直辖市级安全督查检查：' prop='provinceSaInspect'>
                  <div v-if="mode === 'view'">{{dataToView.provinceSaInspect}}</div>
                  <InputNumber v-else class="w" min="0"  type='text' v-model='dataToView.provinceSaInspect'></InputNumber>
                </FormItem>
              </Col>
            </Row>
            <Row type="flex" justify="space-around" class="code-row-bg">
              <Col span="11">
                <FormItem label='接受属地市、区、县级安全督查检查：' prop='districtSaInspect'>
                  <div v-if="mode === 'view'">{{dataToView.districtSaInspect}}</div>
                  <InputNumber v-else class="w" min="0"  type='text' v-model='dataToView.districtSaInspect'></InputNumber>
                </FormItem>
              </Col>
              <Col span="11">
                <FormItem label='因安全问题受到处罚、曝光情况：' prop='saPunishTeims'>
                  <div v-if="mode === 'view'">{{dataToView.saPunishTeims}}</div>
                  <InputNumber v-else class="w" min="0"  type='text' v-model='dataToView.saPunishTeims'></InputNumber>
                </FormItem>
              </Col>
            </Row>
            <Row type="flex" justify="space-around" class="code-row-bg">
              <Col span="11">
                <FormItem label='填表人：' prop='registrant'>
                  <div v-if="mode === 'view'">{{dataToView.createUserName}}</div>
                  <Input v-else type='text' v-model='dataToView.registrant' readonly></Input>
                </FormItem>
              </Col>
              <Col span="11">
                <FormItem label='填表时间：' prop='registTime'>
                  <div v-if="mode === 'view'">{{renderViewDate(dataToView.createDate)}}</div>
                  <DatePicker v-else type="date" placeholder="请选择日期" class="w" v-model='dataToView.registTime' readonly></DatePicker>
                </FormItem>
              </Col>
            </Row>
            <Row type="flex" justify="space-around" class="code-row-bg">
              <Col span="23">
                <FormItem label='备注：' prop='notes'>
                  <div v-if="mode === 'view'">{{dataToView.notes}}</div>
                  <Input v-else  type='textarea' v-model='dataToView.notes'></Input>
                </FormItem>
              </Col>
            </Row>
          </Form>
        </Col>
      </Row>
      <div slot="footer">
        <Button v-if="mode != 'view'" type="primary"  class='ivu-btn-save' @click="submit('dialogForm')" >确定</Button>
        <Button v-if="mode != 'view'" type="primary"  class='ivu-btn-cancel' @click="handleCancel" >取消</Button>
        <Button v-if="mode === 'view'" class='ivu-btn-save' @click="dialogShow=false">关闭</Button>
      </div>
    </Modal> 
    <Modal title="环境监督情况报送表" :transfer=false v-model="environmentDataVisible" :width=1200 footer-hide>
        <Table ref='table' :loading="loading" size="small" class="table" :height=500 no-data-text="没有查询到相关数据!"
                highlight-row stripe border :columns="environmentTableColumns" width="100%" :data="environmentTableData">
        </Table>
        <Page :total="environPagedata.total" :current="environPagedata.fromPage" :pageSize="environPagedata.pageSize"
          @on-change="environPageChange" @on-page-size-change='environPageSizeChange' show-total show-sizer show-elevator/>
    </Modal>
    <Modal title="安全监督检查表" :transfer=false v-model="safeDataVisible" :width=1200 footer-hide>
        <Table ref='table' :loading="loading" size="small" class="table" :height=500 no-data-text="没有查询到相关数据!"
                highlight-row stripe border :columns="safeTableColumns" width="100%" :data="safeTableData">
        </Table>
        <Page :total="safePagedata.total" :current="safePagedata.fromPage" :pageSize="safePagedata.pageSize"
          @on-change="safePageChange" @on-page-size-change='safePageSizeChange' show-total show-sizer show-elevator/>
    </Modal>  
  </Layout>
</template>

<script>
import {Api} from '@/api/index.js'
import {formatDate} from '@/tools/index'
import _deepclone from 'lodash/cloneDeep'
import { mapState, mapGetters, mapActions } from 'vuex'
var cascaderDom = () => import('@/components/cascader-dom.vue');
import pageCommonFunction from '@/components/pageCommonFunction.js'
export default {
  components:{
    cascaderDom
  },
    computed:{
        ...mapState('trhg', {
            areaMap: state => state.area.areaMap?state.area.areaMap:[],
            areaTreeMap: state => state.area.areaTreeMap?state.area.areaTreeMap:{},
        }),
    },
  data(){
    return{
      ...this.createCommonDataField(),
      columns1: [
        { title: '序号', width: 80, fixed: 'left', align: 'center', render: (h, params) => {
            if(params.row.id === '-1') return h('span', "汇总");
            return h('span', (params.index - 1) + (this.pagedata.currentPage - 1) * this.pagedata.pageSize + 1);
          }},
        // { key:'perfAssessNum',title: '绩效考核责任书编号',  align: 'center', width: 100},
        { key:'companyName',fixed: 'left',title: '企业名称',  align: 'center', width: 260 },
        { key:'rptPeroid',fixed: 'left',title: '月份',  align: 'center', width: 120, render: this.renderCellMonth},
        { key: 'companyAddress', title: '所在地', align: 'center', width: 130, render: this.renderCellArea },
        { key:'stateEnInspect',title: '接受国家部、委环境督查检查',  align: 'center', width: 160 },
        { key:'provinceEnInspect',title: '接受省、自治区、直辖市级环境督查检查',  align: 'center', width: 160 },
        { key:'districtEnInspect',title: '接受属地市、区、县级环境督查检查',  align: 'center',width: 160 },
      //  { key:'enPunishTeims',title: '因环境保护问题受到处罚、曝光情况',  align: 'center', width: 160 }, 
        { key:'stateSaInspect',title: '接受国家部、委安全督查检查',  align: 'center', width: 160 },
        { key:'provinceSaInspect',title: '接受省、自治区、直辖市级安全督查检查',  align: 'center', width: 160 },
        { key:'districtSaInspect',title: '接受属地市、区、县级安全督查检查',  align: 'center', width: 160 },
      //  { key:'saPunishTeims',title: '因安全问题受到处罚、曝光情况',  align: 'center', width: 160 }, 
        { key:'notes',title: '备注',  align: 'center', width: 150, tooltip:true },
        // this.getActionColumns((params) => {
        //   return params.row.id === '-1';
        // }),
		{
		    title: '操作',
		    key: 'action',
		    fixed: 'right',
		    width: 100,
		    align: 'center',
		    render: (h, params) => {
				if(params.index != 0){
					return h('div', [
					    h('A', {
					        props: {
					            type: 'primary',
					            size: 'small'
					        },
					        style: {
					            fontSize: '14px',
					        },
					        on: {
					            click: () => {
					                this.showData(params, 1);
					            }
					        }
					    }, '详情')
					]);
				}
		    }
		},
      ],
      ruleCustom : {
        companyId: [ { required: true, message: '请填写企业名称', trigger: 'change' } ],
        companyAddress: [ { required: true, message: '请填写所在地', trigger: 'change' } ],
        rptPeroid: [ { required: true, message: '请填写月份', trigger: 'change', type:'date' } ],
      },
      tableHeight:10,
      // api
      queryUrl:Api.querySafeRptAcceptInspect,
      exportUrl:Api.exportSafeRptAcceptInspect,
      deleteUrl:Api.deleteSafeRptAcceptInspect,
      bthDeleteUrl:Api.batchDeleteSafeRptAcceptInspect,
      getUrl:Api.getSafeRptAcceptInspect,
      updateUrl:Api.updateSafeRptAcceptInspect,
      saveUrl:Api.saveSafeRptAcceptInspect,
      environmentTableColumns:[ { title: '序号', width: 80, fixed: 'left', align: 'center', render:
              (h, params) => { 
           return h('span', params.index + (this.environPagedata.fromPage - 1) * this.environPagedata.pageSize + 1);}
           },
          // { key:'perfAssessNum',title: '绩效考核责任书编号',  align: 'center', width: 100},
          { key:'companyName',fixed: 'left',title: '被检查企业',  align: 'center', width: 200 },
          { key:'belongOrgName',fixed: 'left',title: '二级集团',  align: 'center', width: 200 },
          { key:'inspectionTime',title: '检查时间',  align: 'center', width: 150, render: this.renderCellDate},
          { key:'inspectionGroupCategory',title: '检查组别',  align: 'center', width: 120,render:(h, params)=>{
            return h('span', this.igcEnMap && this.igcEnMap[params.row.inspectionGroupCategory] && this.igcEnMap[params.row.inspectionGroupCategory].codingName)
          }, },
          { key:'rummager',title: '检查组人员',  align: 'center', width: 200  },
          { key:'issueCount',title: '问题数量',  align: 'center', width: 100  },
          { key:'issueCompletionCount',title: '整改完成问题数量',  align: 'center', width: 150  },
		  { key:'contentIssue',title: '检查内容及发现问题',  align: 'center', width: 200 , tooltip:true },
          { key:'issueRectificationRequest',title: '问题及整改要求',  align: 'center', width: 200, tooltip:true  },
          { key:'issueCompletion',title: '问题整改完成情况',  align: 'center', width: 200, tooltip:true  },
          { key:'issueCompletionTime',title: '整改完成时间',  align: 'center', width: 150, render: this.renderCellDate  },
          { key:'createDate',title: '填表时间',  align: 'left', width: 120,  render: this.renderCellDate }
           ],
      environmentTableData:[],
      environmentDataVisible:false,
      environPagedata:{
        total:0,
        fromPage:1,
        pageSize:10
      },
      safeTableColumns:[{ title: '序号', width: 80, fixed: 'left', align: 'center', render:
        (h, params) => { 
           return h('span', params.index + (this.safePagedata.fromPage - 1) * this.safePagedata.pageSize + 1);}
           },
          // { key:'perfAssessNum',title: '绩效考核责任书编号',  align: 'center', width: 100},
          { key:'companyName',fixed: 'left',title: '被检查企业',  align: 'center', width: 200 },
          { key:'belongOrgName',fixed: 'left',title: '二级集团',  align: 'center', width: 200 },
          { key:'inspectionTime',title: '检查时间',  align: 'center', width: 150, render: this.renderCellDate},
          { key:'inspectionGroupCategory',title: '检查组别',  align: 'center', width: 120,render:(h, params)=>{
            return h('span', this.igcSaMap && this.igcSaMap[params.row.inspectionGroupCategory] && this.igcSaMap[params.row.inspectionGroupCategory].codingName)
          }, },
          { key:'rummager',title: '检查组人员',  align: 'center', width: 200  },
          { key:'issueCount',title: '问题数量',  align: 'center', width: 100  },
          { key:'issueCompletionCount',title: '整改完成问题数量',  align: 'center', width: 150  },
		  { key:'contentIssue',title: '检查内容及发现问题',  align: 'center', width: 200 , tooltip:true },
          { key:'issueRectificationRequest',title: '问题及整改要求',  align: 'center', width: 200, tooltip:true  },
          { key:'issueCompletion',title: '问题整改完成情况',  align: 'center', width: 200, tooltip:true  },
          { key:'issueCompletionTime',title: '整改完成时间',  align: 'center', width: 150, render: this.renderCellDate  },
          { key:'createDate',title: '填表时间',  align: 'left', width: 120,  render: this.renderCellDate },
      ],
      igcEnMap:{},
      igcSaMap:{},
      safeTableData:[],
      safeDataVisible:false,
      safePagedata:{
        total:0,
        fromPage:1,
        pageSize:10
      },
      loading:false,
      currentCellCategoryArray:[],
    }
  },
  async mounted() {
      this.tableHeight = window.innerHeight - 250;
      this.pageStatus.baseLoading = true
      await this.$store.dispatch('trhg/area/query', {scope:this}, { root: true })
      await this.$http.get(Api.queryCodeDetailBySortId + '/IGC-000002', {params: {}}).then((res) => {
            this.igcSaMap = this.dictListToMap(res.data.data);
        });
      await this.$http.get(Api.queryCodeDetailBySortId + '/IGC-000001', {params: {}}).then((res) => {
            this.igcEnMap = this.dictListToMap(res.data.data);
        });
      this.pageStatus.baseLoading = false
    this.query();
      this.tempAreaTree = this.areaTreeMap['0']
  },
  methods:{
    ...pageCommonFunction,
    localRowClassName(row, index) {
        if (row.id === '-1') 
            return 'local-table-summary-row';
        else
            return '';
    },
    switchQuery(flag) {
        this.switchFlag = flag;
        if (!this.switchFlag) {
            this.tableHeight = window.innerHeight - 250;
        } else {
            this.tableHeight = window.innerHeight - 280;
        }
      },
    cellClicked(row, column, data, event){
      if(row.id === '-1'){
        if(column.key == "stateEnInspect"){
          this.currentCellCategoryArray = ['IGC-000001000000001','IGC-000001000000002'];
          this.showEnvironData();
        }else if(column.key == "provinceEnInspect"){
          this.currentCellCategoryArray = ['IGC-000001000000003'];
          this.showEnvironData();
        }else if(column.key == "districtEnInspect"){
          this.currentCellCategoryArray = ['IGC-000001000000004','IGC-000001000000005'];
          this.showEnvironData();
        }else if(column.key == "enPunishTeims"){
          this.showEnvironData(data);
        }else if(column.key == "stateSaInspect"){
          this.currentCellCategoryArray = ['IGC-000002000000001','IGC-000002000000002'];
          this.showSafeData();
        }else if(column.key == "provinceSaInspect"){
          this.currentCellCategoryArray = ['IGC-000002000000003'];
          this.showSafeData();
        }else if(column.key == "districtSaInspect"){
          this.currentCellCategoryArray = ['IGC-000002000000004','IGC-000002000000005'];
          this.showSafeData();
        }else if(column.key == "saPunishTeims"){
          this.showSafeData();
        }
      }
    },
    showEnvironData(){
      this.environPagedata.total = 0;
      this.environmentDataVisible = true;
      this.queryEnvironData();
    },
    showSafeData(){
      this.safePagedata.total = 0;
      this.safeDataVisible = true;
      this.querySafeData();
    },
    environPageChange(pageNum) {
      this.environPagedata.fromPage = pageNum;
      this.queryEnvironData();
    },
    environPageSizeChange(pageSize) {
      this.environPagedata.pageSize = pageSize;
      this.queryEnvironData();
    },
    safePageChange(pageNum) {
      this.safePagedata.fromPage = pageNum;
      this.querySafeData();
    },
    safePageSizeChange(pageSize) {
      this.safePagedata.pageSize = pageSize;
      this.querySafeData();
    },
    querySafeData(){
        this.loading = true;
        let data = {
            startPage: this.safePagedata.fromPage,
            size: this.safePagedata.pageSize,
            conditions:{
              inspectionGroupCategory: this.currentCellCategoryArray,
              companyId:this.dataToQuery.companyId,
              inspectionTimeFrom:this.dataToQuery.monthFrom
            }
        };
        if(this.dataToQuery.monthTo){
            var date = new Date(this.dataToQuery.monthTo)
            date.setMonth(date.getMonth() + 1);
            let lastDay = date.setDate(0);
            data.conditions.inspectionTimeTo = this.formatDate(new Date(lastDay), 'yyyy-MM-dd');
        }
        if(this.dataToQuery.yearDate) {
          data.conditions.inspectionTimeFrom = this.dataToQuery.yearDate.getFullYear() + "-01-01";
          data.conditions.inspectionTimeTo = this.dataToQuery.yearDate.getFullYear() + "-12-31";
        }
        let url = Api.querySuperviseInspect + '/2';
        this.$http.post(url, data).then((res) => {
            this.safeTableData = res.data.data.data;
            this.safePagedata.total = res.data.data.totalSize;
            this.loading = false;
        }).catch(e => {
            this.$Message.error("数据获取失败")
        })
    },
    queryEnvironData(){
        this.loading = true;
        let data = {
            startPage: this.environPagedata.fromPage,
            size: this.environPagedata.pageSize,
            conditions:{
              inspectionGroupCategory: this.currentCellCategoryArray,
              companyId:this.dataToQuery.companyId,
              inspectionTimeFrom:this.dataToQuery.monthFrom
            }
        };
        if(this.dataToQuery.monthTo){
            var date = new Date(this.dataToQuery.monthTo)
            date.setMonth(date.getMonth() + 1);
            let lastDay = date.setDate(0);
            data.conditions.inspectionTimeTo = this.formatDate(new Date(lastDay), 'yyyy-MM-dd');
        }
        if(this.dataToQuery.yearDate) {
          data.conditions.inspectionTimeFrom = this.dataToQuery.yearDate.getFullYear() + "-01-01";
          data.conditions.inspectionTimeTo = this.dataToQuery.yearDate.getFullYear() + "-12-31";
        }
        let url = Api.querySuperviseInspect + '/1';
        this.$http.post(url, data).then((res) => {
            this.environmentTableData = res.data.data.data;
            this.environPagedata.total = res.data.data.totalSize;
            this.loading = false;
        }).catch(e => {
            this.$Message.error("数据获取失败")
        })
    },
    monthToChange(date){
      this.dataToQuery.monthTo = date + '-01';
      var date = new Date(this.dataToQuery.monthTo)
      date.setMonth(date.getMonth() + 1);
      let lastDay = date.setDate(0);
      this.dataToQuery.monthTo = this.formatDate(new Date(lastDay), 'yyyy-MM-dd');
    },
      beforeEditDialogOpen(data) {
          if(data.row.companyAddress){
              data.row.companyAddressArr = data.row.companyAddress.split(',')
              data.row.companyAddressName = this.areaCodeToAreaName(data.row.companyAddress)
          }
      },
      async afterDataToViewInit(data) {
          if (data && data.companyAddress) {
              let companyAddressArr = data.companyAddress.split(',')
              this.tempAreaTree = []
              setTimeout(() => {
                  this.tempAreaTree = this.addressEditArr(this.areaTreeMap,companyAddressArr)
              }, 100)
          }
      },
    deleteData(params) {
      this.deleteDateAjax(params);
    },
    query() {
	  if(this.dataToQuery.monthFrom == '-01'){
	  	this.dataToQuery.monthFrom = null
	  }
	  if(this.dataToQuery.monthTo == '-01'){
	  	this.dataToQuery.monthTo = null
	  }
      if(this.dataToQuery.yearDate) {
        this.dataToQuery.year = this.dataToQuery.yearDate.getFullYear();
      }
        if (this.dataToQuery.saInspects != null && this.dataToQuery.saInspects != undefined && this.dataToQuery.saInspects.length < 1) {
            this.dataToQuery.saInspects=null
        }
        if (this.dataToQuery.enInspects != null && this.dataToQuery.enInspects != undefined && this.dataToQuery.enInspects.length < 1) {
            this.dataToQuery.enInspects=null
        }
      this.queryAjax();
    },
    submit(name) {
        this.$set(this.dataToView,'companyAddress',this.dataToView.companyAddressArr.join(','))
        if(this.dataToView.stateEnInspect == '')  this.dataToView.stateEnInspect = 0;
        if(this.dataToView.provinceEnInspect == '')  this.dataToView.provinceEnInspect = 0;
        if(this.dataToView.districtEnInspect == '')  this.dataToView.districtEnInspect = 0;
        if(this.dataToView.enPunishTeims == '')  this.dataToView.enPunishTeims = 0;
        if(this.dataToView.stateSaInspect == '')  this.dataToView.stateSaInspect = 0;
        if(this.dataToView.provinceSaInspect == '')  this.dataToView.provinceSaInspect = 0;
        if(this.dataToView.districtSaInspect == '')  this.dataToView.districtSaInspect = 0;
        if(this.dataToView.saPunishTeims == '')  this.dataToView.saPunishTeims = 0;
        this.submitAjax(name);
    },
    createEmptyDataToAdd(){
      return {
        stateEnInspect:'',
        provinceEnInspect:'',
        districtEnInspect:'',
        enPunishTeims:'',
        stateSaInspect:'',
        provinceSaInspect:'',
        districtSaInspect:'',
        saPunishTeims:'',
        companyAddressArr:[],
      }
    },
	showData(data, flag) {
		
    this.dataToView = JSON.parse(JSON.stringify(data.row));
    console.log(this.dataToView);
	    this.dialogShow = true; 
	},
  formatDate(date, fmt) {
      if (/(y+)/.test(fmt)) {
          fmt = fmt.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length));
      }
      let o = {
          'M+': date.getMonth() + 1,
          'd+': date.getDate(),
          'h+': date.getHours(),
          'm+': date.getMinutes(),
          's+': date.getSeconds()
      };
      for (let k in o) {
          if (new RegExp(`(${k})`).test(fmt)) {
              let str = o[k] + '';
              fmt = fmt.replace(RegExp.$1, RegExp.$1.length === 1 ? str : this.padLeftZero(str));
          }
      }
      return fmt;
  },
  padLeftZero(str) {
      return ('00' + str).substr(str.length);
  },
  },
  watch:{
  },
}
</script>

<style>

.ivu-table .local-table-summary-row {
	border-top: 1px solid #e8eaec;
	background-color: #f8f8f9;
  cursor:pointer;
}

.ivu-table .local-table-summary-row td {
	border-right: 1px solid #e8eaec;
	background-color: #f8f8f9;
  cursor:pointer;
}
</style>
